/* DownLoadServlet.java
 *
 * Project/Product: GWC_BS
 *
 * Modify Information:
 * =============================================================================
 *   Author Date       Description
 *   ---------- ---------- ---------------------------------------------------
 *   Administrator  2008-1-29   First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2008
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */
package system.imp;

import java.io.FileInputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class GWDownLoadServlet extends javax.servlet.http.HttpServlet {
   
    public GWDownLoadServlet()
    {
        super();
    }
    
    public void init() throws ServletException
    {
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws javax.servlet.ServletException, java.io.IOException
    {
       performTask(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws javax.servlet.ServletException, java.io.IOException
    {
        performTask(request, response);
    }

    public void performTask(HttpServletRequest req, HttpServletResponse res)
        throws javax.servlet.ServletException, java.io.IOException
    {
        //获取参数
        String tableName = (String)req.getParameter("tableName");
        if (tableName == null) tableName = "";
        String type = (String)req.getParameter("type");
        if (type == null) type = ""; 
        String warehouseCode = (String)req.getParameter("warehousecode");
        if (warehouseCode == null) warehouseCode = ""; 
        String lastUpdateTime = (String)req.getParameter("lastupdatetime");
        if (lastUpdateTime == null) lastUpdateTime = ""; 
        
        String strDownFileName = "";
        String serverPath = req.getRealPath("/");
        
        if (!serverPath.endsWith("\\"))
        {
            serverPath +="\\";
        }
        
        //生成excel文件并保存到固定位置
        strDownFileName = CreateDownLoadExcelProcessor.createDownLoadExcelByDB(serverPath,tableName,type,warehouseCode,lastUpdateTime);        
       
        //返回excel文件路径
        String strTime = "";
        try{
            strTime = system.imp.DateUtil.getCurrTime();
        }
        catch(Exception e)
        {
        }
        PrintWriter tOutput = res.getWriter();
        tOutput.print(strDownFileName);
    }
}
